import json


def read_jsonl(json_file_path):
    """读取 JSONL 文件并返回一个包含所有对象的列表"""
    data = []
    try:
        with open(json_file_path, 'r', encoding='utf-8') as f:
            for line in f:
                # 跳过空行
                if line.strip():
                    try:
                        # 解析当前行的 JSON 对象
                        obj = json.loads(line)
                        data.append(obj)
                    except json.JSONDecodeError as e:
                        print(f"Error decoding line: {line.strip()}")
                        print(f"Error details: {e}")
    except FileNotFoundError:
        print(f"文件不存在: {json_file_path}")
    except Exception as e:
        print(f"读取文件时发生错误: {e}")
    return data


if __name__ == "__main__":
    # 读取 JSONL 文件
    items = read_jsonl('c:/Tmp/results/output_0d70c7dcd5677991342ae8f88506d6d962cd384c.jsonl')

    # 打印读取的内容
    if items:
        print(f"成功读取 {len(items)} 个 JSON 对象")
        for i, item in enumerate(items, 1):
            print(f"\n对象 {i}:")
            result = json.dumps(item['text'], indent=2, ensure_ascii=False)
            print(result)

    else:
        print("没有读取到有效数据")